package xju_5_6.springboot_5_6.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import xju_5_6.springboot_5_6.entity.Friend;

@RestController
public class UserController {

    @Value("${friend.username}")
    private String username;
    @Value("${friend.age}")
    private String age;
    @Value("${pets[2]}")
    private String pet;

    @Autowired
    private Environment environment;

    @Autowired
    private Friend friend;


    @GetMapping("test")
    public String test(@RequestParam(required = false,defaultValue = "springboot") String name) {
        System.out.println(username);
        System.out.println(age);
        System.out.println(pet);

        System.out.println("----------");
        System.out.println(environment.getProperty("friend.username"));
        System.out.println(environment.getProperty("friend.age"));
        System.out.println(environment.getProperty("pets[2]"));
        System.out.println(friend);
        return "test:"+name;
    }
}
